<?php
$GLOBALS['PAGE_FORM_DATA'] = array();
$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';
$dt = new DataTable(constant('DB_TABLE_EPAPER_SEND_QUEUE'));
if ( $act == 'save') {
	$row_data = $_REQUEST;
	$row_data['send_datetime'] = $row_data['send_date'].' '.$row_data['send_time'];
	$row_data['send_member'] = isset($row_data['send_member'] )?'Y':'N';
	$dt->save($row_data);
	ob_clean();
	$redirect_url = 'epaper-wait.php';
	header('Location:'.$redirect_url);
	exit();
}
else if ( $act == 'edit' )
{
	$GLOBALS['PAGE_FORM_DATA'] = $dt->get($_REQUEST['id']);
	$dt = new DataTable(constant('DB_TABLE_EPAPER_CONTENT'));
	$epaper_row = $dt->get($GLOBALS['PAGE_FORM_DATA']['epaper_id']);
	if ( $epaper_row){
		$GLOBALS['PAGE_FORM_DATA']['epaper_subject'] = $epaper_row['subject'];
	}else{
		$GLOBALS['PAGE_FORM_DATA']['epaper_subject'] = '';
	}
	$GLOBALS['PAGE_FORM_DATA']['send_date'] = date('Y-m-d',strtotime($GLOBALS['PAGE_FORM_DATA']['send_datetime']));
	$GLOBALS['PAGE_FORM_DATA']['send_time'] = date('H:i:s',strtotime($GLOBALS['PAGE_FORM_DATA']['send_datetime']));

}
else {
	$GLOBALS['PAGE_FORM_DATA']['id'] = 0;

	$GLOBALS['PAGE_FORM_DATA']['epaper_id'] = '';
	$GLOBALS['PAGE_FORM_DATA']['epaper_subject'] = '';
	$GLOBALS['PAGE_FORM_DATA']['send_date'] = date('Y-m-d');
	$GLOBALS['PAGE_FORM_DATA']['send_time'] = '02:00:00';
	$GLOBALS['PAGE_FORM_DATA']['send_member'] = 'Y';
	$GLOBALS['PAGE_FORM_DATA']['email_address'] = '';
}
?>